<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    div {
        width: 500px;
        height: 400px;
        border: 1px solid;
        position: relative;
    }

    p {
        width: 30px;
        height: 30px;
        position: absolute;
        top: 0;
        left: 0;
        background-color: orange;
    }
</style>

<body>
    <div id="box">
        <p></p>
    </div>
</body>

</html>

<script>
    function fn(callback, play) {
        let last = null
        return function () {
            let start = +new Date()
            if (start - last > play) {
                callback()
                last = start
            }
        }
    }
    let div = document.querySelector('div')
    div.onmousemove = fn(() => {
        let p = document.querySelector('p')
        console.log('111');
        p.style.left = event.offsetX + 'px'
        p.style.top = event.offsetY + 'px'
    }, 200)



</script>